#include "RsGisLibMorCreateCirOp.h"
#include "ExtensionManager.h"
#include "ExtensionSession.h"
#include <QVariant>

RsGisLibMorCreateCirOp::RsGisLibMorCreateCirOp(RsgisPortal* ClientPortal, QWidget *parent)
{
	ui = new Ui::RsGisLibMorCreateCirOp();
	ui->setupUi(this);

	Portal = ClientPortal;

	connect(ui->pushButton_OutputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_OutputFilePath_clicked()));
	connect(ui->pushButton_CreateCirOp, SIGNAL(clicked()), this, SLOT(on_action_Button_CreateCirOp_clicked()));

	ui->textBrowser_ParameterDescription->setText(
		"op_size - is a integer specifying the size of the operator"
	);

	ui->textBrowser_ParameterDescription->setEnabled(false);

	ui->lineEdit_OutputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\TestOpSize");

	ui->lineEdit_OpSize->setText("5");

	ui->lineEdit_Priority->setText("16");
}

void RsGisLibMorCreateCirOp::on_action_Button_OutputFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_OutputFilePath->setText(str.toUtf8());
}

void RsGisLibMorCreateCirOp::on_action_Button_CreateCirOp_clicked()
{
	{
		if (ui->lineEdit_OutputFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Output File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_OpSize->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Operation Size is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_Priority->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Priority is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}
	}

	QList<QVariant> SysParaList;
	SysParaList << QVariant(QString("RsGisLib"));
	SysParaList << QVariant(QString("Morphology"));
	SysParaList << QVariant(int(ui->lineEdit_Priority->text().toInt()));

	QList<QVariant> AlgParaList;
	AlgParaList << QVariant(QString("CreateCirOp"));
	AlgParaList << QVariant(QString(ui->lineEdit_OutputFilePath->text()));
	AlgParaList << QVariant(int(ui->lineEdit_OpSize->text().toInt()));

	QVariantList ArgList;
	ArgList << (QVariant)SysParaList;
	ArgList << (QVariant)AlgParaList;

	Portal->goAhead(ArgList);
}